<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use dosamigos\datetimepicker\DateTimePicker;
use common\models\project\Project;

/* @var $this yii\web\View */
/* @var $model common\models\projectsummary\ProjectSummary */
/* @var $form yii\widgets\ActiveForm */
?>

<?= Html::jsFile('@web/js/angular.min.js')?>

<div class="project-summary-form" ng-controller="menuDesigner">

    <?php $form = ActiveForm::begin(); ?>
    <div class="row">
        <div class="col-md-2">
            <?= $form->field($model, 'number')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'cname')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'category')->dropDownList(Project::getArrayCategory()) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'bearunit')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'amount_subsidy')->textInput(['maxlength' => true]) ?>
        </div>
    </div>
    <div class="row">
        <div class="col-md-2">
                        <div>
                <div class="form-group field-classteam-starttime required" style="width: 250px">
                    <label class="control-label" for="classteam-starttime">开始时间</label>
                    <?= DateTimePicker::widget([
                        'model' => $model,
                        'attribute' => 'starttime',
                        'language' => 'zh-CN',
                        'size' => 'ms',
                        'clientOptions' => [
                            'autoclose' => true,
                            'linkFormat' => 'yyyy-mm-dd  HH:ii ',
                            'todayBtn' => true
                        ]
                    ]);?>
                </div>
            </div>
        </div>
        <div class="col-md-2">
                        <div>
                <div class="form-group field-classteam-starttime required" style="width: 250px">
                    <label class="control-label" for="classteam-starttime">结束时间</label>
                    <?= DateTimePicker::widget([
                        'model' => $model,
                        'attribute' => 'endtime',
                        'language' => 'zh-CN',
                        'size' => 'ms',
                        'clientOptions' => [
                            'autoclose' => true,
                            'linkFormat' => 'yyyy-mm-dd  HH:ii ',
                            'todayBtn' => true
                        ]
                    ]);?>
                </div>
            </div>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'proj_leader')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'proj_telephone')->textInput(['maxlength' => true]) ?>
        </div>
    </div>
    
    <?= $form->field($model, 'proj_summ')->widget('kucha\ueditor\UEditor',[]) ?>

    <?= $form->field($model, 'registration_form')->widget('kucha\ueditor\UEditor',[]) ?>

    <?= $form->field($model, 'bear_option')->widget('kucha\ueditor\UEditor',[]) ?>

    <?= $form->field($model, 'mana_option')->widget('kucha\ueditor\UEditor',[]) ?>


    <div class="row">
        <div class="col-md-2">
            <?= $form->field($model, 'depart_leader')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'total_appropriation')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'surplus')->textInput(['maxlength' => true]) ?>
        </div>
    </div>




    <table class="table table-bordered">
        <thead>
            <tr>
                <th>编号</th>
                <th>支出内容</th>
                <th>金额</th>
                <th>备注</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <?php if(is_array($model->actual_item)) { ?>
            <?php foreach ($model->actual_item as $k=>$t) { ?>

            <tr class="tplpaid">
                <td>
                    
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectSummary[actual_item][]" value="<?= $t ?>"/>
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectSummary[paid_money][]" value="<?= $model->paid_money[$k] ?>"/>
                </td>
                <td>
                    <input class="form-control" type="text" name="ProjectSummary[paid_note][]" value="<?= $model->paid_note[$k] ?>"/>
                </td>                
                <td>
                    <button style="margin-top: 24px;<?php if ($k == 0) { ?>display: none<?php } ?>" class="btn btn-warning btn-sm" type="button" id="delpaid">删除</button>
                    <button style="margin-top: 24px;<?php if ($k != 0) { ?>display: none<?php } ?>" class="btn btn-info btn-sm addpaid" ng-click="addpaid();" type="button">添加</button>
                </td>
            </tr>

            <?php } ?>
            <?php } else { ?>

            <tr class="tplpaid">
                <td>
                    
                </td>
                <td>
                    <?= $form->field($model, 'actual_item[]')->textInput(['maxlength' => true]) ?>
                </td>
                <td>
                    <?= $form->field($model, 'paid_money[]')->textInput(['maxlength' => true]) ?>
                </td>
                <td>
                    <?= $form->field($model, 'paid_note[]')->textInput(['maxlength' => true]) ?>
                </td>                
                <td>
                    <button style="margin-top: 24px;display: none" class="btn btn-warning btn-sm" type="button" id="delpaid">删除</button>
                    <button style="margin-top: 24px" class="btn btn-info btn-sm addpaid" ng-click="addpaid();" type="button">添加</button>
                </td>
            </tr>
            <?php } ?>
        </tbody>
    </table>

    <div class="row">
        <div class="col-md-2">
            <?= $form->field($model, 'fina_leader')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-2">
            <?= $form->field($model, 'lister')->textInput(['maxlength' => true]) ?>
        </div>
    </div>


    <?= $form->field($model, 'file_name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'file_description')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'proj_size')->textInput(['maxlength' => true]) ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<?php $this->beginBlock('footer_scripts'); ?>

<script>
    angular.module('app', []).controller('menuDesigner', function ($scope, $http) {

        //支出
        var paidlength = 1;
        $("body").on("click", ".addpaid", function() {

            paidlength +=1;
            
            var clone = $(this).parent().parent().clone();
            clone.find('button').eq(1).hide();
            clone.find('button').eq(0).show();
            $(this).parent().parent().parent().append(clone);
        });

        $("body").on("click", "#delpaid", function() {
            paidlength -=1;
            $(this).parents(".tplpaid").remove();
        });
    });
    angular.bootstrap(document, ['app']);
</script>
<?php $this->endBlock(); ?>